from fastapi import FastAPI
import uvicorn
import os
from lly.server import root_path
from starlette.staticfiles import StaticFiles
from lly.server.routers import vim, security, user, android, filetool
from fastapi.exceptions import RequestValidationError
from fastapi.encoders import jsonable_encoder
from typing import List
from starlette.responses import Response, PlainTextResponse, HTMLResponse, JSONResponse
from starlette.requests import Request
'''
start command : uvicorn lly.server.main:app --reload --port 12345
start command help :uvicorn --help
'''
app = FastAPI(
    title='FastApi use',
    description='hello world',
    version='1.0.1',
)


#  @app.exception_handler(RequestValidationError)
#  async def validation_exception_handler(request: Request, exc: RequestValidationError):
    #  print(exc.body)
    #  return JSONResponse(
        #  status_code=422,
        #  content=jsonable_encoder({"detail": exc.errors(), "body": exc.body}),
    #  )

app.mount('/static', StaticFiles(directory=root_path+'static'), name='static')
app.include_router(vim.router, prefix='/vim', tags=['vim'])
app.include_router(filetool.router, prefix='/files', tags=['files'])
app.include_router(android.router, prefix='/android', tags=['android'])
app.include_router(security.router)
app.include_router(user.router)

if __name__ == '__main__':
    #  uvicorn.run(app, host='127.0.0.1', port=12345)
    from lly.server import start_server
    start_server()
